package com.xiaomei.manager.utils;

import java.util.Calendar;

public class BirthdayConverterUtils {

	private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 };
	private final static String[] constellationArr = new String[] { "摩羯座",
		"水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座",
		"天蝎座", "射手座", "摩羯座" };
	private final static String[] years = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊",
            "猴", "鸡", "狗", "猪" };
	
	/**
	 * 拆分生日(1990-06-06)
	 * @param birthday
	 * @return
	 */
	public static String[] splitBirthday(String birthday) {
		if(birthday == null) {
			return null;
		}
		return birthday.split("-");
	}
	
	/**
	  * @param birth_year
	  * @return
	  *             根据年份获取年龄;
	  */
	public static Integer getAge(int birth_year) {
		// 获取当前年份
		Calendar calendar = Calendar.getInstance();
		int current_year = calendar.get(Calendar.YEAR);
 
		return current_year - birth_year;
	}
	
	/**
	 * Java通过生日计算星座
	 * 
	 * @param month
	 * @param day
	 * @return
	 */
	public static String getConstellation(int month, int day) {
	    return day < dayArr[month - 1] ? constellationArr[month - 1]
	            : constellationArr[month];
	}
	
	/**
	 * 通过生日计算属相
	 * 
	 * @param year
	 * @return
	 */
	public static String getZodiac(int year) {
	    if (year < 1900) {
	        return "未知";
	    }
	    int start = 1900;
	    
	    return years[(year - start) % years.length];
	}
	
	public static void main(String[] args) {
		System.out.println(getConstellation(10, 26));
	}
}
